﻿var defServidor = '200.62.177.254';
var defNombre = 'GSP1';
var defPuerto = '80';
var defProtocolo = 'http';
var nombreEmpresa = 'Grupo Crystalis';

loadCss();

function imagen() {
    panelPrincipal.setActiveItem(loginForm, { type: 'fade'});
}

function Tick(ele, loginForm) {
    setTimeout('imagen()',2000);
    //ele.setActiveItem(loginForm, { type: 'slide', direction: 'right', duration: 300 });
}

function loadCss() {    
    var osName;
    if (Ext.is.Android) {
        osName = 'Android'
    }
    if (Ext.is.Blackberry) {
        osName = 'BlackBerry'
    }
    if (Ext.is.iOS) {
        osName = 'iOS'
    }
    var	cssName;
    switch (osName) {
        case 'Android':
            cssName = 'android.css';
            break;
        case 'BlackBerry':
            cssName = 'bb.css';
            break;
        case 'iOS':
            cssName = 'ios.css';
            break;
        default:
            cssName = 'sencha-touch.css';
    }
    var $ = document; // shortcut
    var head = $.getElementsByTagName('head')[0];
    var link = $.createElement('link');
    link.id = 'pOS';
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = 'resources/css/' + cssName;
    head.appendChild(link);
}

function hostValue(ser, nom, pue, pro, formName) {
    var acceso;
    if (nom == 'undefined') { nom = ''; }

    acceso = Ext.ModelMgr.create({
        servidor: ser,
        nombre: nom,
        puerto: pue,
        protocolo: pro,
        hostValue: (nom == "" ? pro + '://' + ser + ':' + pue : pro + '://' + ser + ':' + pue + '/' + nom)
    }, 'accesoModel');
    var sto = Ext.getStore('accesoStore');
    sto.getProxy().clear();
    sto.data.clear();
    sto.sync();
    sto.add(acceso);
    sto.sync();
    if (formName != 'loginForm') {
        formName.setActiveItem(formName.items.items[1], { type: 'slide', direction: 'left' });
    }
}

function validateUser(storeName) {
    var item = storeName.getAt(0);
    if (!item) {
        window.open('index.html', '_self');
    }
}

function ltrim(s) {
    var l = 0;
    while (l < s.length && s[l] == 0)
    { l++; }
    return s.substring(l, s.length);
}

function prepareForm(formName, SAPUserStore) {
    //--añadir campos hidden
    formName.add({ xtype: 'hiddenfield', id: 'UserId', name: 'UserId', value: SAPUserStore.getAt(0).data.Uname });
    formName.add({ xtype: 'hiddenfield', id: 'PwdId', name: 'PwdId', value: SAPUserStore.getAt(0).data.Passwd });
    formName.add({ xtype: 'hiddenfield', id: 'Id', name: 'Id', value: SAPUserStore.getAt(0).data.Id });
}